// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ATServlet.java

package WEB-INF.classes.com.actimind.actitime;

import java.io.IOException;
import java.sql.Driver;
import java.util.Hashtable;
import java.util.Properties;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionServlet;

public class ATServlet extends ActionServlet
{

    public ATServlet()
    {
        app_context = null;
    }

    public void init()
        throws ServletException
    {
        initDBParameters();
        app_context = getServletContext();
        String title_prefix = getAppParameter("title-prefix");
        app_context.setAttribute("title-prefix", title_prefix != null ? ((Object) (title_prefix)) : "");
        super.init();
    }

    public static Properties initDBParameters()
        throws ServletException
    {
        Properties props = new Properties();
        ClassLoader loader = ClassLoader.getSystemClassLoader();
        java.io.InputStream inputStream = loader.getResourceAsStream("com/actimind/actitime/AT.properties");
        if(inputStream == null)
        {
            loader = (com.actimind.actitime.util.Capsule.class).getClassLoader();
            if(loader != null)
                inputStream = loader.getResourceAsStream("com/actimind/actitime/AT.properties");
            if(inputStream == null)
                throw new RuntimeException("Failed to load com/actimind/actitime/AT.properties");
        }
        try
        {
            props.load(inputStream);
        }
        catch(IOException ex)
        {
            throw new RuntimeException("Error while loading com/actimind/actitime/AT.properties: " + ex);
        }
        try
        {
            drv = (Driver)Class.forName(props.getProperty("DBdriver")).newInstance();
        }
        catch(Exception e)
        {
            throw new ServletException("Can't create Driver", e);
        }
        url = props.getProperty("DBurl");
        props = new Properties();
        props.put("user", props.getProperty("DBuser"));
        props.put("password", props.getProperty("DBpassword"));
        return props;
    }

    public void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException
    {
        disableCaching(res);
        super.doGet(req, res);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException
    {
        disableCaching(res);
        super.doPost(req, res);
    }

    private void disableCaching(HttpServletResponse res)
    {
        if(res != null)
        {
            res.setContentType("text/html");
            res.addHeader("Cache-Control", "no-cache");
            res.addHeader("Pragma", "no-cache");
            res.setDateHeader("Expires", System.currentTimeMillis() - 0x80befc000L);
        }
    }

    public String getAppParameter(String parameter)
    {
        return app_context.getInitParameter(parameter);
    }

    private ServletContext app_context;
    private static final String dbPropsName = "com/actimind/actitime/AT.properties";
    public static Driver drv;
    public static String url;
    public static Properties props;
}
